package com.example.administrator.compileapp.drawer;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.administrator.compileapp.R;
import com.example.administrator.compileapp.bean.PersonInformationy;
import com.example.administrator.compileapp.databinding.ActivityEditorBinding;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class EditorActivity extends AppCompatActivity implements View.OnClickListener {
   private ActivityEditorBinding binding;
    private List<PersonInformationy> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_editor);
        Bundle bundle = getIntent().getBundleExtra("bundle");
       list = (List<PersonInformationy>) bundle.getSerializable("list");
        binding.setEditorPersonInformationy(list.get(0));
        init();
    }

    private void AboutIntent() {
        Intent intent = new Intent();
        Bundle bundle = new Bundle();
        List<PersonInformationy> list = new ArrayList<>();
        String nickName = String.valueOf(binding.editorNickName.getText());
        String nickSex = String.valueOf(binding.editorNickSex.getText());
        String nickAge = String.valueOf(binding.editorNickAge.getText());
        String nickPhone = String.valueOf(binding.editorNickPhone.getText());
        String nickBirtherday = String.valueOf(binding.editorNickBirtherday.getText());
        String nickEmile = String.valueOf(binding.editorNickEmile.getText());
        String nickInfo = String.valueOf(binding.editorNickInfo.getText());
        PersonInformationy informationy = new PersonInformationy(nickName,nickSex,nickAge,nickBirtherday,nickEmile,nickPhone,nickInfo);
        list.add(informationy);
        bundle.putSerializable("list", (Serializable) list);
        intent.putExtra("bundle",bundle);
        setResult(RESULT_OK,intent);
    }

    private void init() {
        binding.editorBack.setOnClickListener(this);
        binding.editorFinish.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.editor_finish:
                AboutIntent();
                Toast.makeText(this, "完成", Toast.LENGTH_SHORT).show();
                finish();
                break;
            case R.id.editor_back:
                finish();
                overridePendingTransition(0,R.anim.activity_exit);
                break;
        }
    }
}
